/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is Forte for Java, Community Edition. The Initial
* Developer of the Original Code is Sun Microsystems, Inc. Portions
* Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.vcs.util;
import java.util.Vector;
import java.awt.event.*;
/**
* Dialog that enables users to set variable values before running the command.
*
* @author Martin Entlicher
* @version
*/
public class VariableInputDialog extends javax.swing.JDialog {
private static final int TEXTFIELD_COLUMNS = 20;
private boolean validInput = false;
private javax.swing.JLabel[] varPromptLabels;
private javax.swing.JTextField[] varPromptFields;
private javax.swing.JCheckBox[] varAskCheckBoxes;
static final long serialVersionUID = 8363935602008486018L;
/** Creates new form VariableInputDialog */
public VariableInputDialog(java.awt.Frame parent, boolean modal) {
super (parent, modal);
initComponents ();
getRootPane().setDefaultButton(okButton);
cancelButton.setMnemonic(KeyEvent.VK_C);
promptEachCheckBox.setMnemonic(KeyEvent.VK_P);
setTitle(org.openide.util.NbBundle.getBundle(VariableInputDialog.class).getString("VariableInputDialog.title"));
pack ();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
inputPanel = new javax.swing.JPanel ();
variablePanel = new javax.swing.JPanel ();
promptEachSeparator = new javax.swing.JSeparator ();
promptEachCheckBox = new javax.swing.JCheckBox ();
buttonPanel = new javax.swing.JPanel ();
okButton = new javax.swing.JButton ();
cancelButton = new javax.swing.JButton ();
getContentPane ().setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints1;
addKeyListener (new java.awt.event.KeyAdapter () {
public void keyPressed (java.awt.event.KeyEvent evt) {
formKeyPressed (evt);
}
}
);
addWindowListener (new java.awt.event.WindowAdapter () {
public void windowClosing (java.awt.event.WindowEvent evt) {
closeDialog (evt);
}
}
);
inputPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints2;
inputPanel.setBorder (new javax.swing.border.EtchedBorder());
variablePanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints3;
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints2.insets = new java.awt.Insets (8, 8, 0, 8);
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.weighty = 1.0;
inputPanel.add (variablePanel, gridBagConstraints2);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridy = 1;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.insets = new java.awt.Insets (0, 8, 0, 8);
gridBagConstraints2.weightx = 1.0;
inputPanel.add (promptEachSeparator, gridBagConstraints2);
promptEachCheckBox.setText (org.openide.util.NbBundle.getBundle(VariableInputDialog.class).getString("VariableInputDialog.promptEachCheckBox.text"));
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridy = 2;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.insets = new java.awt.Insets (8, 8, 8, 8);
gridBagConstraints2.weightx = 1.0;
inputPanel.add (promptEachCheckBox, gridBagConstraints2);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints1.insets = new java.awt.Insets (8, 8, 8, 8);
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.weighty = 1.0;
getContentPane ().add (inputPanel, gridBagConstraints1);
buttonPanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints4;
okButton.setText (org.openide.util.NbBundle.getBundle(VariableInputDialog.class).getString("VariableInputDialog.okButton.text"));
okButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
okButtonActionPerformed (evt);
}
}
);
gridBagConstraints4 = new java.awt.GridBagConstraints ();
gridBagConstraints4.weightx = 1.0;
buttonPanel.add (okButton, gridBagConstraints4);
cancelButton.setText (org.openide.util.NbBundle.getBundle(VariableInputDialog.class).getString("VariableInputDialog.cancelButton.text"));
cancelButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed (evt);
}
}
);
gridBagConstraints4 = new java.awt.GridBagConstraints ();
gridBagConstraints4.weightx = 1.0;
buttonPanel.add (cancelButton, gridBagConstraints4);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridy = 1;
gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints1.insets = new java.awt.Insets (0, 8, 8, 8);
gridBagConstraints1.weightx = 1.0;
getContentPane ().add (buttonPanel, gridBagConstraints1);
}//GEN-END:initComponents
private void formKeyPressed (java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
// Add your handling code here:
if (evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
cancelButtonActionPerformed(null);
}
}//GEN-LAST:event_formKeyPressed
private void cancelButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
// Add your handling code here:
validInput = false;
closeDialog(null);
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
// Add your handling code here:
validInput = true;
closeDialog(null);
}//GEN-LAST:event_okButtonActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
setVisible (false);
dispose ();
}//GEN-LAST:event_closeDialog
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel inputPanel;
private javax.swing.JPanel variablePanel;
private javax.swing.JSeparator promptEachSeparator;
private javax.swing.JCheckBox promptEachCheckBox;
private javax.swing.JPanel buttonPanel;
private javax.swing.JButton okButton;
private javax.swing.JButton cancelButton;
// End of variables declaration//GEN-END:variables
/**
* Show the dialog and wait for user input.
* @return <code>true</code> if OK,
* <code>false</code> if dialog was canceled
*/
public boolean showDialog() {
MiscStuff.centerWindow(this);
show();
return validInput;
}
/**
* Create variable labels and text fields.
*/
public void setVarPromptLabels(String[] varLabels) {
Vector labels = new Vector();
Vector fields = new Vector();
for(int i = 0; i < varLabels.length; i++) {
javax.swing.JLabel label = new javax.swing.JLabel(varLabels[i]+":");
javax.swing.JTextField field = new javax.swing.JTextField(TEXTFIELD_COLUMNS);
java.awt.GridBagConstraints gridBagConstraints1 = new java.awt.GridBagConstraints ();
java.awt.GridBagConstraints gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = i;
gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints1.insets = new java.awt.Insets (0, 0, 8, 8);
gridBagConstraints2.gridx = 1;
gridBagConstraints2.gridy = i;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.insets = new java.awt.Insets (0, 0, 8, 0);
variablePanel.add(label, gridBagConstraints1);
variablePanel.add(field, gridBagConstraints2);
labels.addElement(label);
fields.addElement(field);
MiscStuff.removeEnterFromKeymap(field);
}
pack();
this.varPromptLabels = (javax.swing.JLabel[]) labels.toArray(new javax.swing.JLabel[0]);
this.varPromptFields = (javax.swing.JTextField[]) fields.toArray(new javax.swing.JTextField[0]);
}
/**
* Create variable labels and check boxes.
*/
public void setVarAskLabels(String[] varLabels) {
Vector chboxes = new Vector();
for(int i = 0; i < varLabels.length; i++) {
javax.swing.JCheckBox chbox = new javax.swing.JCheckBox(" "+varLabels[i]);
java.awt.GridBagConstraints gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridx = 0;
gridBagConstraints1.gridy = i + varPromptLabels.length;
gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST;
gridBagConstraints1.insets = new java.awt.Insets (0, 0, 8, 0);
variablePanel.add(chbox, gridBagConstraints1);
chboxes.addElement(chbox);
}
pack();
this.varAskCheckBoxes = (javax.swing.JCheckBox[]) chboxes.toArray(new javax.swing.JCheckBox[0]);
}
/**
* Set whether to show check box for prompt on next file. When not called default is true.
* @param show true to show, false not to show
*/
public void showPromptEach(boolean show) {
promptEachCheckBox.setVisible(show);
promptEachSeparator.setVisible(show);
pack();
}
/**
* Set whether the initial state of the check box for prompt on next file. When not called default is false.
* @param prompt the initial state
*/
public void setPromptEach(boolean prompt) {
promptEachCheckBox.setSelected(prompt);
}
/**
* Get the variable prompt values.
*/
public String[] getVarPromptValues() {
String[] varValues = new String[varPromptFields.length];
for(int i = 0; i < varPromptFields.length; i++) {
varValues[i] = varPromptFields[i].getText();
}
return varValues;
}
/**
* Get the variable ask values.
*/
public String[] getVarAskValues() {
String[] varValues = new String[varAskCheckBoxes.length];
for(int i = 0; i < varAskCheckBoxes.length; i++) {
varValues[i] = (varAskCheckBoxes[i].isSelected()) ? "true" : "";
}
return varValues;
}
/**
* Whether to prompt for variables for each file separately or use these variables for all files.
*/
public boolean getPromptForEachFile() {
return promptEachCheckBox.isSelected();
}
}